﻿using System;

namespace _005_C_语言基本元素概览_初识类型_变量与方法_算法简介
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //推断类型关键字
            var X = 30;
            Console.WriteLine(X.GetType().Name);//Int32
            int a = 1, b = 2;
            int x = new Cals().Add(a, b);
            Console.WriteLine(x);//3
            Console.WriteLine(new Cals().Today());
            new Cals().Division(1, 2);
            //new Cals().Print();
            new Cals().PrintFor(3);

            Console.WriteLine(new Cals().SumFormX(100));
        }

        //方法
    }

    class Cals
    {
        public int Add(int a, int b)
        {
            return a + b;
        }

        public string Today()
        {
            int day = DateTime.Now.Day;
            return day.ToString();
        }

        //没有数值返回
        public void Division(int a, int b)
        {
            Console.WriteLine(a / b);
        }

        public void Print()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(i);
            }
        }


        //递归算法

        public void PrintFor(int X)
        {
            if (X == 1)
            {
                Console.WriteLine(X);
            }

            else
            {
                Console.WriteLine(X);
                PrintFor(X - 1);
            }

        }

        //递归计算 几个数的总和

        public int SumFormX(int X)
        {
            if (X == 1)
            {
                return 1;
            }

            else
            {
                int result = 0;
                result += X + SumFormX(X - 1);
                return result;
            }
        }
    }
}
